package org.eiahe.hr.salary.controller;

import lombok.RequiredArgsConstructor;
import org.ehe.common.core.BaseController;
import org.ehe.common.core.domain.R;
import org.ehe.common.core.utils.StringUtils;
import org.ehe.common.core.validate.AddGroup;
import org.ehe.common.core.validate.EditGroup;
import org.ehe.common.core.validate.QueryGroup;
import org.ehe.common.log.annotation.Log;
import org.ehe.common.log.enums.BusinessType;
import org.ehe.common.mybatis.core.page.PageQuery;
import org.ehe.common.mybatis.core.page.TableDataInfo;
import org.eiahe.hr.salary.domain.bo.HousingFundPaymentBo;
import org.eiahe.hr.salary.domain.vo.HousingFundPaymentVo;
import org.eiahe.hr.salary.service.IHousingFundPaymentService;
import org.ehe.common.excel.utils.ExcelUtil;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import cn.dev33.satoken.annotation.SaCheckPermission;

import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 公积金缴纳Controller
 *
 * @author zhangnn
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/salary/housingFund")
public class HousingFundPaymentController extends BaseController {

    private final IHousingFundPaymentService iHousingFundPaymentService;

    /**
     * 查询公积金缴纳列表
     */
    @SaCheckPermission("salary:housingFund:list")
    @GetMapping("/list")
    public TableDataInfo<HousingFundPaymentVo> list(HousingFundPaymentBo bo, PageQuery pageQuery) {
        return iHousingFundPaymentService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出公积金缴纳列表
     */
    @SaCheckPermission("salary:housingFund:export")
    @Log(title = "公积金缴纳", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HousingFundPaymentBo bo, HttpServletResponse response) {
        List<HousingFundPaymentVo> list = iHousingFundPaymentService.queryList(bo);
        ExcelUtil.exportExcel(list, "公积金缴纳数据", HousingFundPaymentVo.class, response);
    }

    /**
     * 获取公积金缴纳详细信息
     *
     * @param paymentId 主键
     */
    @SaCheckPermission("salary:housingFund:query")
    @GetMapping("/{paymentId}")
    public R<HousingFundPaymentVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable("paymentId") Long paymentId) {
        return R.ok(iHousingFundPaymentService.queryById(paymentId));
    }

    /**
     * 新增公积金缴纳
     */
    @SaCheckPermission("salary:housingFund:add")
    @Log(title = "公积金缴纳", businessType = BusinessType.INSERT)
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody HousingFundPaymentBo bo) {
        return toAjax(iHousingFundPaymentService.insertByBo(bo));
    }

    /**
     * 修改公积金缴纳
     */
    @SaCheckPermission("salary:housingFund:edit")
    @Log(title = "公积金缴纳", businessType = BusinessType.UPDATE)
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody HousingFundPaymentBo bo) {
        return toAjax(iHousingFundPaymentService.updateByBo(bo));
    }

    /**
     * 删除公积金缴纳
     *
     * @param paymentIds 主键串
     */
    @SaCheckPermission("salary:housingFund:remove")
    @Log(title = "公积金缴纳", businessType = BusinessType.DELETE)
    @DeleteMapping("/{paymentIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] paymentIds) {
        return toAjax(iHousingFundPaymentService.deleteWithValidByIds(Arrays.asList(paymentIds)));
    }
}